﻿using System;
using System.Collections.Generic;
using System.Text;

namespace VisionCloud.Utility.Extensions
{
    public static class VersionExtension
    {
        /// <summary>
        /// 跟目标版本比较是否较新版本
        /// </summary>
        /// <param name="version"></param>
        /// <param name="sourceVersion"></param>
        /// <returns></returns>
        public static bool IsNewVersion(this string version, string sourceVersion)
        {
            try
            {
                if (string.IsNullOrEmpty(version) || string.IsNullOrEmpty(sourceVersion))
                    return false;
                var versionArr = version.Split('.');
                var sourceVersionArr = sourceVersion.Split('.');
                for (int i = 0; i < versionArr.Length; i++)
                {
                    if (string.Compare(versionArr[i], sourceVersionArr[i], StringComparison.OrdinalIgnoreCase) > 0)
                        return true;
                    //if (int.Parse(versionArr[i]) < int.Parse(sourceVersionArr[i]))
                    //    return true;
                }
                return false;
            }
            catch (Exception ex)
            {
                Logger.Error("版本号格式不正确", ex);
                return false;
            }
        }
    }
}
